<?php
/**
 * Joomla! 1.5 component ArticleCashRewards
 *
 * @version $Id: helper.php 2009-05-10 01:47:01 svn $
 * @author Maverick
 * @package helpers
 * @subpackage ArticleCashRewards
 * @license GNU/GPL
 * Website: http://www.boddunan.com
 *
 * Review and approve the articles and assign points and cash rewards.
 * Users can see their articles and the points/cash rewards assigned in the front-end module.
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

class ArticlecashrewardsHelper {
    function sendEmail($sender_email, $sender_name, $recievers, $subject, $body ){
        foreach ($recievers as $email){
            if(!in_array($email, $sent)) {

                $mail =& JFactory::getMailer();
                $sender = array( $sender_email, $sender_name );
                
                $mail->setSender($sender);
                $mail->addRecipient($email);
                $mail->setSubject($subject);
                $mail->setBody($body);

                $mail->send();
                $sent[] = $email;
            }
        }
    }

    function generatePassword ($length = 10){
      // start with a blank password
      $password = "";

      // define possible characters
      $possible = "0123456789BCDFGHJKMNPQRSTUVXYZ";

      // set up a counter
      $i = 0;

      // add random characters to $password until $length is reached
      while ($i < $length) {

        // pick a random character from the possible ones
        $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);

        // we don't want this character if it's already in the password
        if (!strstr($password, $char)) {
          $password .= $char;
          $i++;
        }

      }

      // done!
      return $password;

    }

}
?>